<?php

class Application_Model_DbTable_TrachNhiem extends Zend_Db_Table_Abstract
{

    protected $_name = 'TRACHNHIEM';

    
    function getDataPermission(){
        $select = $this->select();
        $select->from( array('tn'=>"TRACHNHIEM"),array('MaNghiepVu'=>'tn.MaNghiepVu','MaNhom'=>'tn.MaNhom','ChoPhep'=>'tn.ChoPhep') )
               ->join( array('nv'=>'NGHIEPVU'),"nv.MaNghiepVu=tn.MaNghiepVu AND nv.show=1", array('TenNghiepVu'=>'nv.TenNghiepVu','TrinhBay'=>'nv.show','controller'=>'nv.controller_name','action'=>'nv.action_name') )
               ->join( array('nh'=>'NHOMTAIKHOAN'),"nh.MaNhom=tn.MaNhom", array( 'TenNhom'=>'nh.TenNhom' ) )
               ->order("CapDo desc")
               ->order("controller asc")
               ->order("action asc")
               ->setIntegrityCheck(false);
        return $this->fetchAll($select);
    }
    
    public function findRow( $controller,$action ){
        $select = $this->select();
        $select->from( array('tn'=>"TRACHNHIEM") )
               ->join( array('nv'=>'NGHIEPVU'),"nv.MaNghiepVu=tn.MaNghiepVu AND controller_name='$controller' AND action_name='$action'" )
               ->setIntegrityCheck(false);
        return $this->fetchRow($select);
    }
}

